import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import NProgress from 'nprogress'
import { loading } from '@/utils/loading'
import 'nprogress/nprogress.css'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'index',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/login/index.vue')
  },
  {
    path: '/layout',
    name: 'layout',
    redirect: '/bigScreen',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '/bigScreen', // 大屏控制
        name: 'bigScreen',
        component: () => import('@/pages/bigScreen/index.vue')
      },
      {
        path: '/test',
        name: 'test',
        component: () => import('@/pages/test/index.vue')
      },
      {
        path: '/pvParamter', // 实时参数/光伏参数
        name: 'pvParamter',
        component: () => import('@/pages/pv/parameter/index.vue'),
        children: [
          {
            path: '/pvParamter/device/:type/:id',
            name: 'pvDevice',
            props: true,
            component: () => import('@/pages/pv/parameter/device/index.vue')
          },
          {
            path: '/pvParamter/group/:type/:id',
            name: 'pvGroup',
            props: true,
            component: () => import('@/pages/pv/parameter/group/index.vue')
          },
          {
            path: '/pvParamter/station/:type/:id',
            name: 'pvStation',
            props: true,
            component: () => import('@/pages/pv/parameter/station/index.vue')
          },
          {
            path: '/pvParamter/site/:type/:id',
            name: 'pvSite',
            props: true,
            component: () => import('@/pages/pv/parameter/site/index.vue')
          },
          {
            path: '/pvParamter/company/:type/:id',
            name: 'pvCompany',
            props: true,
            component: () => import('@/pages/pv/parameter/company/index.vue')
          }
        ]
      },
      {
        path: '/pvMonitor', // 视频监控
        name: 'pvMonitor',
        component: () => import('@/pages/pv/monitor/index.vue')
      },
      {
        path: '/pvSvg', // SVG图
        name: 'pvSvg',
        component: () => import('@/pages/bigScreen/index.vue')
      },
      {
        path: '/pvReportPower', // 报表管理/光伏报表/发电统计
        name: 'pvReportPower',
        component: () => import('@/pages/pv/report/power/index.vue')
      },
      {
        path: '/pvReportIncome', // 报表管理/光伏报表/收益统计
        name: 'pvReportIncome',
        component: () => import('@/pages/pv/report/income/index.vue')
      },
      {
        path: '/pvReportEfficiency', // 报表管理/光伏报表/发电效率
        name: 'pvReportEfficiency',
        component: () => import('@/pages/pv/report/efficiency/index.vue')
      },
      {
        path: '/pvOpsOrder', // 运维管理/工单记录
        name: 'pvOpsOrder',
        component: () => import('@/pages/pv/ops/order/index.vue')
      },
      {
        path: '/pvOpsPlan', // 运维管理/运维计划
        name: 'pvOpsPlan',
        component: () => import('@/pages/pv/ops/plan/index.vue')
      },
      {
        path: '/pvOpsRecord', // 运维管理/运维记录
        name: 'pvOpsRecord',
        component: () => import('@/pages/pv/ops/record/index.vue')
      },
      {
        path: '/pvEnergyPower', // 能效分析/光伏分析/发电统计
        name: 'pvEnergyPower',
        component: () => import('@/pages/pv/energy/power/index.vue')
      },
      {
        path: '/pvEnergyIncome', // 能效分析/光伏分析/收益统计
        name: 'pvEnergyIncome',
        component: () => import('@/pages/pv/energy/income/index.vue')
      },
      {
        path: '/pvEnergyEfficiency', // 能效分析/光伏分析/发电效率
        name: 'pvEnergyEfficiency',
        component: () => import('@/pages/pv/energy/efficiency/index.vue')
      },
      // 报警分析
      {
        path: '/pvAlarmRealTime', // 实时报警
        name: 'pvAlarmRealTime',
        component: () => import('@/pages/pv/alarm/realtime/index.vue')
      },
      {
        path: '/pvAlarmHistory', // 历史报警
        name: 'pvAlarmHistory',
        component: () => import('@/pages/pv/alarm/history/index.vue')
      },
      {
        path: '/pvAlarmCount', // 报警统计
        name: 'pvAlarmCount',
        component: () => import('@/pages/pv/alarm/count/index.vue')
      },
      // 档案管理
      {
        path: '/pvArchiveCompany',
        name: 'pvArchiveCompany',
        component: () => import('@/pages/pv/archive/company/index.vue')
      },
      {
        path: '/pvArchiveSite',
        name: 'pvArchiveSite',
        component: () => import('@/pages/pv/archive/site/index.vue')
      },
      {
        path: '/pvArchiveStation',
        name: 'pvArchiveStation',
        component: () => import('@/pages/pv/archive/station/index.vue')
      },
      {
        path: '/pvArchiveGroup',
        name: 'pvArchiveGroup',
        component: () => import('@/pages/pv/archive/group/index.vue')
      },
      {
        path: '/pvArchiveDevice',
        name: 'pvArchiveDevice',
        component: () => import('@/pages/pv/archive/device/index.vue')
      }
    ]
  },
  {
    path: '/:pathMatch(.*)',
    name: 'notFound',
    redirect: '/login'
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})
let existLoading = false
router.beforeEach((to, from, next) => {
  if (!existLoading) {
    loading.show()
    existLoading = true
  }
  NProgress.start()
  next()
})
router.afterEach(() => {
  if (existLoading) {
    loading.hide()
  }
  NProgress.done()
})
export default router
